package com.yyl.systemdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyl.entity.RRolePermission;
import com.yyl.systemdemo.dao.RRolePermissionMapper;
import com.yyl.systemdemo.service.IRRolePermissionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RRolePermissionServiceImpl extends ServiceImpl< RRolePermissionMapper,RRolePermission> implements IRRolePermissionService {

    @Resource
    private RRolePermissionMapper rolePermissionMapper;
    @Override
    public boolean updPermission(String roleId, String menuids) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("role_id",roleId);
        // 删除当前的角色的权限
        int delete = rolePermissionMapper.delete(queryWrapper);
        //  添加新的权限
        String[] split = menuids.split(",");
        for (String s : split) {
            //
            RRolePermission rolePermission  = new RRolePermission();

            String id = System.currentTimeMillis() + "";
            rolePermission.setId(id);
            rolePermission.setPermissionId(s);
            rolePermission.setRoleId(roleId);
            rolePermissionMapper.insert(rolePermission);
        }
        return true;
    }
}
